package hv.fmw.core.configure {
	import hv.fmw.core.assets.AssetsManager;
	import hv.fmw.core.command.Command;
	import hv.fmw.core.command.ICommand;
	import hv.fmw.utils.Config;
	import hv.fmw.utils.Labels;

	import flash.events.Event;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	/**
	 * @author hvong
	 */
	public class ConfigureXMLCmd extends Command implements ICommand {
		
		public function ConfigureXMLCmd() {
		}
		
		public function execute() : void {
			var loader:URLLoader = new URLLoader();
				loader.addEventListener(Event.COMPLETE, _onCommandComplete);
				loader.load(new URLRequest(Config.getPath("config")));
		}

		private function _onCommandComplete(event : Event) : void {
			var data:XML = new XML(event.target.data);
			
			// Set paths, vars... etc
			Config.configure(data);
			
			// Populate assets
			AssetsManager.getInstance().add(data..asset);
			
			// Set Labels
			Labels.populate(XMLList(data..text));
			
			super.complete();
		}
	}
}
